﻿using System;
using System.Collections;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Intepreter;
using ILRuntime.CLR.Method;

namespace ILRuntime
{
    public class LevelScriptAdaptor : CrossBindingAdaptor
    {
        static CrossBindingMethodInfo<System.Int32> mStartLevel = new CrossBindingMethodInfo<System.Int32>("StartLevel");
        static CrossBindingMethodInfo<System.Single> mOnUpdate = new CrossBindingMethodInfo<System.Single>("OnUpdate");
        static CrossBindingMethodInfo mStopLevel = new CrossBindingMethodInfo<System.Int32>("StopLevel");

        public override Type BaseCLRType => typeof(global::Battle.ILevelScript);

        public override Type AdaptorType => typeof(Adapter);

        public override object CreateCLRInstance(Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance)
        {
            return new Adapter(appdomain, instance);
        }

        public class Adapter : global::Battle.ILevelScript, CrossBindingAdaptorType
        {
            ILTypeInstance instance;
            ILRuntime.Runtime.Enviorment.AppDomain appdomain;

            public Adapter()
            {

            }

            public Adapter(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance)
            {
                this.appdomain = appdomain;
                this.instance = instance;
            }

            public ILTypeInstance ILInstance => instance;

            public void StartLevel(int level)
            {
                mStartLevel.Invoke(this.instance, level);
            }

            public void OnUpdate(float deltaTime)
            {
                mOnUpdate.Invoke(this.instance, deltaTime);
            }

            public void StopLevel()
            {
                mStopLevel.Invoke(this.instance);
            }
        }
    }
}
